package com.sky.controller.admin;

import com.sky.config.RedisConfiguration;
import com.sky.mapper.user.MerchantMapper;
import com.sky.pojo.Merchant;
import com.sky.result.Result;
import com.sky.vo.ShopVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "店铺相关接口")
@Slf4j
public class ShopController {
    private static final String KEY = "SHOP_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private MerchantMapper merchantMapper;

    @PutMapping("/admin/shop/{status}")
    @ApiOperation("修改店铺营业状态")
    public Result setStatus(@PathVariable Integer status){
        log.info("修改店铺营业状态为{}",status);
        redisTemplate.opsForValue().set(KEY,status);
        return Result.success();
    }

    @GetMapping("/admin/shop/status")
    @ApiOperation("获取店铺营业状态")
    public Result getStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
        log.info("获取店铺营业状态:{}",status);
        return Result.success(status);
    }

    /*@PutMapping("/user/shop/{status}")
    @ApiOperation("修改店铺营业状态")
    public Result setUserStatus(@PathVariable Integer status){
        log.info("修改店铺营业状态为{}",status);
        redisTemplate.opsForValue().set(KEY,status);
        return Result.success();
    }*/

    @GetMapping("/user/shop/status")
    @ApiOperation("获取店铺营业状态")
    public Result getUserStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
        log.info("获取店铺营业状态:{}",status);
        return Result.success(status);
    }
    @GetMapping("/user/shop/getMerchantInfo")
    @ApiOperation("获取商家信息")
    public Result   getMerchantInfo(){
        //  获取唯一商家对象信息
        Merchant merchant = merchantMapper.findById(1L);
        String  shopName = merchant.getShopName();
        String  shopAddress = merchant.getShopAddress();
        String  shopTelephone = merchant.getShopTelephone();
        ShopVO build = ShopVO.builder().phone(shopTelephone).shopName(shopName).shopAddress(shopAddress).build();
        return  Result.success(build);
    }
}
